import { API_LIST } from '../../../Api/Api'
import { commonTableList } from '../Common/common'
import {
    SelectButton,
    DelDataButton,
    ExecuteButton,
    TestDetailsButton,
    SelectExcelButton,
    ModDataButton,
    OpenSelection,
} from '../Common/options'
import { LabHandleType, DataSynchronization, ProjectList } from '../Common/Conversion'

export const LabUniversalRebar = async ({ url, OptionsEvent, ClientData, Permission, actionRef }) => {
    const { hostname } = window.location
    const labHandleType = await LabHandleType()
    const centNameOptions = await DataSynchronization()
    let data = {
        pageSize: 10,
        get: API_LIST()[`get${url}OC`],
        added: `pos${url}`,
        modify: `put${url}`,
        delete: `del${url}`,
        params: { pageIndex: 1, OGroupId: 'asc@998' },
        options: [
            // 批量审核
            Permission.findIndex(v => v.uuid === '730008cc-ece7-4eeb-a9e3-fe553c57655b') !== -1 && (
                <OpenSelection
                    OptionsEvent={OptionsEvent}
                    title="批量审核"
                    data={{
                        type: 'SelectLabAuditStatus',
                        value2: 'LabUniversalRebarMapping',
                        url: 'posUpdateAuditStatus',
                    }}
                />
            ),
            // 批量填写原因
            Permission.findIndex(v => v.uuid === 'ea3d0b1e-a912-4714-89f3-fe34fb1ac83f') !== -1 && (
                <OpenSelection
                    OptionsEvent={OptionsEvent}
                    title="批量填写原因"
                    data={{
                        type: 'SelectLabHandleType',
                        handle: labHandleType,
                        value2: 'LabUniversalRebarMapping',
                        url: 'posUpdateLabHandleType',
                    }}
                />
            ),
            <SelectExcelButton
                key="excel"
                title="下载Excel"
                OptionsEvent={OptionsEvent}
                api={API_LIST()['getLabUniversalRebarExcel']}
            />,
        ],
        columns: [
            commonTableList.uuid,
            { ...commonTableList.SearchSort, selectType: 'LabUniversalRebar' },
            {
                ...commonTableList.projectUuid,
                valueEnum: await ProjectList(),
                hideInAdded: true,
                hideInModify: true,
                hideInTable: true,
                hideInSearch: !hostname.includes('jszx'),
            },
            {
                ...commonTableList.organizationUuid,
                valueEnum: ClientData.organization,
                hideInModify: true,
            },
            {
                dataIndex: 'ownerOrganizationName',
                title: '样品来源',
                valueType: 'input',
                hideInModify: true,
                width: 150,
            },
            {
                dataIndex: 'groupName',
                title: '试验组号',
                valueType: 'input',
                width: 150,
            },
            {
                dataIndex: 'testCode',
                title: '试件序号',
                hideInSearch: true,
                valueType: 'input',
                width: 150,
            },
            {
                dataIndex: 'testType',
                title: '试验类别',
                hideInSearch: true,
                ellipsis: true,
                valueType: 'input',
                width: 200,
            },
            {
                dataIndex: 'testDate',
                title: '试验时间',
                hideInSearch: true,
                valueType: 'input',
                width: 200,
            },
            {
                dataIndex: 'nominalDiameter',
                title: '公称直径',
                hideInSearch: true,
                valueType: 'input',
                width: 150,
            },

            {
                dataIndex: 'nominalSectionalArea',
                title: '公称截面面积',
                hideInSearch: true,
                valueType: 'input',
                width: 150,
            },

            {
                dataIndex: 'lowerYield',
                title: '屈服力Fs(kN)',
                hideInSearch: true,
                valueType: 'input',
                width: 150,
            },

            {
                dataIndex: 'lowerYieldStrength',
                title: '屈服点RP(MPa)',
                hideInSearch: true,
                valueType: 'input',
                width: 150,
            },

            {
                dataIndex: 'maximumForce',
                title: '拉断最大力Fm(kN)',
                hideInSearch: true,
                valueType: 'input',
                width: 180,
            },

            {
                dataIndex: 'bendingStrength',
                title: '抗拉强度Rm(MPa)',
                hideInSearch: true,
                valueType: 'input',
                width: 180,
            },

            {
                dataIndex: 'elongationPctAfter',
                title: '断后伸长率A(%)',
                hideInSearch: true,
                valueType: 'input',
                width: 150,
            },
            {
                dataIndex: 'maximumTotalElongation',
                title: '最大力总延伸率(%)',
                hideInSearch: true,
                valueType: 'input',
                width: 200,
            },
            {
                dataIndex: 'elasticityModulus',
                title: '弹性模量E(Gpa)',
                hideInSearch: true,
                valueType: 'input',
                width: 150,
            },
            {
                dataIndex: 'result',
                title: '评定结果',
                rules: true,
                valueType: 'select',
                valueEnum: { 合格: '合格', 不合格: '不合格' },
                width: 150,
            },
            {
                dataIndex: 'labHandleTypeUuid',
                title: '处理意见',
                valueType: 'select',
                hideInModify: true,
                ellipsis: true,
                valueEnum: labHandleType,
                width: 180,
            },
            {
                dataIndex: 'remark',
                title: '说明',
                hideInModify: true,
                valueType: 'input',
                hideInSearch: true,
                ellipsis: true,
                width: 400,
            },
            {
                dataIndex: 'handleUserName',
                title: '填报人',
                hideInModify: true,
                valueType: 'input',
                hideInSearch: true,
                width: 180,
            },
            {
                dataIndex: 'handleTime',
                title: '填报时间',
                hideInModify: true,
                valueType: 'input',
                hideInSearch: true,
                width: 180,
            },
            {
                dataIndex: 'auditStatus',
                title: '审核状态',
                hideInModify: true,
                valueType: 'input',
                hideInSearch: true,
                width: 180,
            },
            {
                dataIndex: 'auditor',
                title: '审核人',
                hideInModify: true,
                valueType: 'input',
                hideInSearch: true,
                width: 180,
            },
            {
                dataIndex: 'auditDate',
                title: '审核时间',
                hideInModify: true,
                valueType: 'input',
                hideInSearch: true,
                width: 180,
            },
            {
                ...commonTableList.isEnabled,
                rules: true,
                hideInSearch: false,
                hideInModify: true,
            },
            {
                dataIndex: 'equipmentName',
                title: '试验机名称',
                valueType: 'input',
                hideInModify: true,
                width: 400,
            },
            {
                dataIndex: 'synced',
                title: '同步',
                valueType: 'select',
                valueEnum: {
                    0: '未同步',
                    1: '已同步',
                },
                width: 150,
                hideInSearch: true,
                hideInAdded: true,
                hideInModify: true,
            },
            commonTableList.BeginStatDate,
            commonTableList.EndStatDate,
            {
                title: '操作',
                valueType: 'systemOperation',
                fixed: 'right',
                width: 460,
                hideInSearch: true,
                hideInAdded: true,
                hideInModify: true,
                render: (_, record) => {
                    const { isEnabled, groupId, synced } = record
                    return [
                        <ModDataButton OptionsEvent={OptionsEvent} key="modify" title="修改" url={url} data={record} />,
                        <TestDetailsButton
                            key="test"
                            title="试验详情"
                            OptionsEvent={OptionsEvent}
                            data={{
                                type: 'LabUniversalRebar',
                                title: '万能机试验详情',
                                data: { groupId },
                            }}
                        />,
                        <SelectButton
                            key="select"
                            title="样品来源"
                            OptionsEvent={OptionsEvent}
                            data={{
                                actionRef,
                                options: ClientData.organization,
                                label: '样品来源',
                                url: 'posLabUniversalRebarSetOwner',
                                uuid: record.uuid,
                            }}
                        />,
                        Permission.findIndex(v => v.uuid === 'ab1b0775-55e1-4ddd-9bf9-37233e5a5467') !== -1 &&
                            synced === 0 && (
                                <SelectButton
                                    key="upload"
                                    title="上传数据"
                                    OptionsEvent={OptionsEvent}
                                    data={{
                                        actionRef,
                                        options: centNameOptions,
                                        label: '上传平台',
                                        url: 'posBCCenterPushPushLabUniversalRebars',
                                        uuid: record.uuid,
                                    }}
                                />
                            ),
                        Permission.findIndex(v => v.uuid === '730008cc-ece7-4eeb-a9e3-fe553c57655b') !== -1 &&
                            isEnabled !== 1 && (
                                <ExecuteButton
                                    actionRef={actionRef}
                                    key="one"
                                    title="启用"
                                    url="posLabUniversalRebarSetIsEnabled"
                                    path={[groupId, 1]}
                                    tips="数据启用成功!"
                                />
                            ),
                        Permission.findIndex(v => v.uuid === '730008cc-ece7-4eeb-a9e3-fe553c57655b') !== -1 &&
                            isEnabled === 1 && (
                                <ExecuteButton
                                    actionRef={actionRef}
                                    key="two"
                                    title="禁用"
                                    danger={true}
                                    url="posLabUniversalRebarSetIsEnabled"
                                    path={[groupId, 0]}
                                    tips="数据禁用成功!"
                                />
                            ),
                        Permission.findIndex(v => v.uuid === 'b008c56f-56c5-4aad-8d94-dd88d92735c9') !== -1 && (
                            <DelDataButton
                                OptionsEvent={OptionsEvent}
                                key="del"
                                title="删除"
                                url={url}
                                uuid={record.uuid}
                            />
                        ),
                    ]
                },
            },
        ],
    }
    return data
}
